/* Change the following definition to match the instruction frequency 
of the application in MIPS (MHz) */

#ifndef DELAY_H
#define DELAY_H

#include "system.h" /*Este archivo define el valor FCY*/
#include <libpic30.h> /*Necesario para __delay32*/

#define Delay_60nS_Cnt    (unsigned long)(60U*(FCY)/1000000000)

#define Delay_150nS_Cnt   (unsigned long)(150ULL*(FCY)/1000000000ULL)
#define Delay_360nS_Cnt   (unsigned long)(360ULL*(FCY)/1000000000ULL)
#define Delay_450nS_Cnt   (unsigned long)(450ULL*(FCY)/1000000000ULL)
#define Delay_600nS_Cnt   (unsigned long)(600ULL*(FCY)/1000000000ULL)
#define Delay_1200nS_Cnt  (unsigned long)(1200ULL*(FCY)/1000000000ULL)

#define Delay1S()              __delay32(FCY)

/* delays specific to each LCD type */
/* delay btw RS/RW signal to E signal */
#define DelayRSSetupTime()     __delay32(Delay_60nS_Cnt) /*min 40ns*/

/* delay btw E rise and Data available */
#define DelayDBOutput()        __delay32(Delay_360nS_Cnt) /*min 100 ns*/
/* min E pulse width low */ /*min 1050 ns = DelayEPulseWidth - DelayEPulseWidthHigh ns*/
#define DelayEPulseWidthLow()  __delay32(Delay_1200nS_Cnt)
/* min E pulse width high */
#define DelayEPulseWidthHigh() __delay32(Delay_150nS_Cnt)
/* E pulse cycle time */
#define DelayEPulseWidth()     __delay32(Delay_1200nS_Cnt) /*min 1200 ns*/
/* min Power On Reset time */
#define DelayPORXLCD()         __delay_ms(40)
/* generic delay for LCD */
#define DelayXLCD()            __delay_us(40)

#define Delay200usXLCD()      __delay_us(200)

#endif /*DELAY_H*/